<template>
  <div class="login-page">
    <div class="van-nav-bar van-hairline--bottom">
      <span></span>
      <h2>账号注册</h2>
    </div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[
        {required: true, message: '请填写用户名'},
        {pattern:/^\w{5,}/,message:'用户名至少为5位'}
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[
        {required: true, message: '请填写密码' },
        {pattern: /^\w{6,}/,message:'密码至少为6位数'}
        ]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit"
          >注册</van-button
        >
       <div class="register"> <router-link class="link" to="/loginlo">注册好了，去登录</router-link></div>
      </div>
    </van-form>
  </div>
</template>

<script>
// 按需导入{}
import { register } from '@/api/user'
export default {
  name: 'login-page',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
    // 往后台发送注册请求了
      await register(values)
      this.$toast.success('注册成功')
      this.$router.push('/loginlo')
    }
  }
}

</script>

<style lang="less" scoped>
.van-hairline--bottom {
  height: 60px;
background-color: #21B97A;
}
h2 {
  color: #fff;
  line-height: 60px;
}
.register {
  width: 160px;
  height: 60px;
  // background-color: pink;
  margin-top: 20px;
  margin-left: 90px;
}
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
</style>
